<template>
  <div>
    <div>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="eidtDetail()" plain>
            新增发票
          </el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="teamlist" size="small">
<!--        <el-table-column label="序号" align="center" prop="id"/>-->
        <el-table-column label="发票金额" align="center" prop="money"/>
        <el-table-column
          prop="type"
          label="状态"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.status==1">通过</el-tag>
            <el-tag type="info" v-if="scope.row.status==0">审批中</el-tag>
            <el-tag type="danger" v-if="scope.row.status==2">驳回</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleViewTeam(scope.row)"
            >查看详情
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <invoiceDetail :visible.sync="detailVisible" :param="param" @getList="getList" :contractData="contractData"></invoiceDetail>
    <invoiceExamine :visible.sync="invoiceVisible" :paramId="invoiveId"></invoiceExamine>
  </div>
</template>

<script>
import {invoicelist, contractlist} from "@/api/system/contract";
import invoiceDetail from "./invoiceDetail";
import invoiceExamine from "./invoiceExamine";

export default {
  name: "index",
  props: ['paramId', 'projectData', 'projectId', 'contractData'], // param 执勤点信息
  dicts: ['sys_stagnation_type'],
  components: {invoiceDetail,invoiceExamine},
  data() {
    return {
      teamlist: [],
      title: '项目执勤点信息',
      // 遮罩层
      loading: true,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        projectId: this.projectId
      },
      zhudianVisible: false,
      invoiceVisible: false,
      paramPoint: null,
      detailVisible: false,
      param: null,
      invoiveId: 0
    }
  },
  watch: {
    projectData(){
      // this.getContract()
    }
  },
  created() {
    this.getList()
    // this.getContract()
  },
  methods: {
    eidtDetail() {
      if (!this.paramId) {
        this.$message.error('未找到相应合同，请先添加合同')
        return
      }
      this.param = JSON.parse(JSON.stringify(this.projectData))
      this.detailVisible = true
    },
    /** 查询定位器列表 */
    getList() {
      this.loading = true;
      invoicelist(this.queryParams).then(response => {
        this.teamlist = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getContract() {
      contractlist({
        pageNum: 1,
        pageSize: 10,
        projectId: this.projectData.id
      }).then(response => {
        console.log('response:', response)
        if (response.rows.length) {
          this.contractData = response.rows[0]
        }
        this.loading = false
      });
    },
    submitForm() {
      if (!this.dealerItem) {
        this.$message.error(this.title)
        return
      }
      let that = this
      console.log('dealerItem:', this.dealerItem, that.queryData)
      // type batchBindingUser 批量绑定设备； bindingUser 单独绑定设备
      if (this.type == 'bindingUser') {
        this.$modal
          .confirm(`确定将该设备绑定至【${this.dealerItem.realName}】,是否继续？`)
          .then(function () {
            return DevideBindingUser({
              deviceIds: [that.queryData.deviceId],
              dealerId: that.dealerItem.adminId
            });
          })
          .then(() => {
            this.$modal.msgSuccess("绑定成功");
            this.$emit('getList')
            this.cancel()
          })
          .catch(() => {
          });
        return
      }
      if (this.type == 'batchBindingUser') {
        this.$modal
          .confirm(`确定为经销商【${this.dealerItem.realName}】批量绑定【${this.queryData.length}】台设备,是否继续？`)
          .then(function () {
            return DevideBindingUser({
              deviceIds: that.queryData,
              dealerId: that.dealerItem.adminId
            });
          })
          .then(res => {
            // this.$modal.msgSuccess("绑定成功");
            // this.messegeFn(res.msg)
            this.$emit('getList')
            this.cancel()
          })
          .catch(() => {
          });
        return
      }
      this.$emit('dealerGet', this.dealerItem)
      this.cancel()
    },
    cancel() {
      this.$emit('update:visible', false)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.dealerId = ''
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dealerId = ''
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleViewTeam(row) {
      this.invoiveId = row.id
      this.invoiceVisible = true
    },
    handleUpdate(row) {
      this.paramId = row.id
      this.zhudianVisible = true
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.name + '"执勤点吗？').then(function () {
        return updateStagnationPoint({id: row.id, status: row.status});
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function () {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
  }
}
</script>

<style scoped>

</style>
